package com.itheima.app.mapper;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

//向mq投递关于动态的消息
@Service
public class MQMovementManager {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Reference
    private MovementService movementService;


    //针对动态的操作
    public static final Integer MOVEMENT_PUBLISH = 1;// 发动态
    public static final Integer MOVEMENT_BROWSE = 2;// 浏览动态
    public static final Integer MOVEMENT_LIKE = 3;// 点赞
    public static final Integer MOVEMENT_LOVE = 4;// 喜欢
    public static final Integer MOVEMENT_COMMENT = 5;// 评论
    public static final Integer MOVEMENT_DISLIKE = 6;// 取消点赞
    public static final Integer MOVEMENT_DISLOVE = 7;// 取消喜欢

    //投递消息(向mq投递消息)
    public void sendMovementMsg(String movementId,Integer type){
        //根据动态id查询动态详情
        Movement movement = movementService.findMyMovementById(movementId);

        //map   pid(唯一标识这个动态)  type   userId
        HashMap<String, Object> map = new HashMap<>();
        map.put("pid",movement.getPid());
        map.put("type",type);
        map.put("userId", UserHolder.getUser().getId());

        //将上面消息投递到mq
        rocketMQTemplate.convertAndSend("recommend-movement",map);
    }
}
